﻿//
//生成部门Path
function fnBuildDeptPath() {
    var parentid = getPar1("ParentID");
    instance[0].ParentID = parentid;
    $.get("/Extend/AjaxData/DataAction.aspx?parentId=" + parentid + "&entity=dept&action=createDeptPath&r=" + Math.random(),
            function (d, t) {
                $("#DeptPath").val(d);
            });
}


function _CallBack() {
    if (getPar1("id") == "") {
        parent.AddNewNode(instance[0].DeptID, instance[0].DeptName);
    }
}


if (getPar1("id") == "") {
    setTimeout(fnBuildDeptPath, 200);
}
var isEdit = false;
var fnCreateCompany = function () {
    isEdit = false;
    //得到当前选中的节点
    currentNode = tree1.getHighlightedNode();  
    document.getElementById("EditUIWindow").src = "CreatDepartment.aspx?deptType=1&r=" + Math.random() + "&parentId=" + fkey + "";
    YAHOO.example.container.dialog1.show();
}
var fnCreateSubCompany = function () {
    isEdit = false;
    //得到当前选中的节点
    currentNode = tree1.getHighlightedNode();  
    document.getElementById("EditUIWindow").src = "CreatDepartment.aspx?deptType=1&r=" + Math.random() + "&parentId=" + fkey + "";
    YAHOO.example.container.dialog1.show();
}
var fnCreateDepartmnet = function () {
    isEdit = false;
    //得到当前选中的节点
    currentNode = tree1.getHighlightedNode();  
    document.getElementById("EditUIWindow").src = "CreatDepartment.aspx?deptType=2&r=" + Math.random() + "&parentId=" + fkey + "";
    YAHOO.example.container.dialog1.show();
}
var fnCreateSubDepartment = function () {
    isEdit = false;
    //得到当前选中的节点
    currentNode = tree1.getHighlightedNode();  
    document.getElementById("EditUIWindow").src = "CreatDepartment.aspx?deptType=2&r=" + Math.random() + "&parentId=" + fkey + "";
    YAHOO.example.container.dialog1.show();
}
var fnEditDepartment = function () {
    isEdit = true;
    document.getElementById("EditUIWindow").src = "CreatDepartment.aspx?deptType=" + deptType + "&r=" + Math.random() + "&DeptId=" + fkey + "";
    YAHOO.example.container.dialog1.show();
}
//移动
var fnMove = function () {
    document.getElementById("EditUIWindow").src = "CopyDepartment.aspx?r=" + Math.random() + "&DeptId=" + fkey + "&allowCheck=false";
    YAHOO.example.container.dialog1.show();
    SetDWH(20, 600, YAHOO.example.container.dialog1);
}
function fnCustomDelete() {
    fnDeleteDepartment();
    }
//
var fnDeleteDepartment = function () {
    //alert("");
    if (confirm("删除公司或部门将会同时删除下级部门,删除后将无法恢复,确定要删除吗?")) {
        var SaveUrl = "../../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=DatDepartment" + "&id=" + fkey;
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;

                    if (str == "1") {
                        alert("数据删除成功");
                        deleteNode();
                    }
                    else {
                        alert(str + "\n" + "数据删除失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
}
